package org.ilead.iserve.model;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Table;

import org.ilead.iserve.service.manager.AreaManager;

/**
 * 用户详细信息
 * User entity. @author MyEclipse Persistence Tools
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "user", catalog = "lop")
public class User implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	// Fields

	private Integer id;
	/**
	 * 用户注册的登录名
	 */
	private String loginName;
	private String password;
	private String userName;
	private Date birthday;
	/**
	 * 性别，false表示女，true表示男
	 */
	private Boolean sex;
	private String phone;
	private String qq;
	private String email;
	/**
	 * 用户头像的保存路径
	 */
	private String image;
	/**
	 * 用户审核状态，0表示未通过，1表示通过
	 */
	private Integer state = 0;
	/**
	 * 用户所在牧区Id
	 */
	private Integer areaId;
	/**
	 * 所在小组名称
	 */
	private String groupName;
	/**
	 * 用户权限ID
	 */
	private Integer permission;
	private Date registerTime;
	private Date modifyTime;
	private Date lastLoginTime;
	
	/**
	 * 牧区名称
	 */
	private String areaName;
	
	/**
	 * 个人主页URL
	 */
	private String homePageUrl;
	/**
	 * 个性签名
	 */
	private String signature;
	
	/**
	 * 显示名称(格式为真实名称(登录名))
	 */
	private String displayName; 
	
	// Constructors

	/** default constructor */
	public User() {
	}
	
	public User(String loginName, String password) {
		super();
		this.loginName = loginName;
		this.password = password;
	}

	/** minimal constructor */
	public User(String loginName, String password, String userName,
			Boolean sex, String phone, String qq, String email, Integer state,
			Integer areaId, String groupName, Integer permission,
			Date registerTime) {
		this.loginName = loginName;
		this.password = password;
		this.userName = userName;
		this.sex = sex;
		this.phone = phone;
		this.qq = qq;
		this.email = email;
		this.state = state;
		this.areaId = areaId;
		this.groupName = groupName;
		this.permission = permission;
		this.registerTime = registerTime;
	}

	/** full constructor */
	public User(String loginName, String password, String userName,
			Date birthday, Boolean sex, String phone, String qq, String email,
			String image, Integer state, Integer areaId, String groupName,
			Integer permission, Date registerTime, Date modifyTime,
			Date lastLoginTime) {
		this.loginName = loginName;
		this.password = password;
		this.userName = userName;
		this.birthday = birthday;
		this.sex = sex;
		this.phone = phone;
		this.qq = qq;
		this.email = email;
		this.image = image;
		this.state = state;
		this.areaId = areaId;
		this.groupName = groupName;
		this.permission = permission;
		this.registerTime = registerTime;
		this.modifyTime = modifyTime;
		this.lastLoginTime = lastLoginTime;
	}

	// Property accessors

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getLoginName() {
		return this.loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserName() {
		return this.userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public Date getBirthday() {
		return this.birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Boolean getSex() {
		return this.sex;
	}

	public void setSex(Boolean sex) {
		this.sex = sex;
	}

	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getQq() {
		return this.qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getImage() {
		return this.image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public Integer getState() {
		return this.state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public Integer getAreaId() {
		return this.areaId;
	}

	public void setAreaId(Integer areaId) {
		this.areaId = areaId;
	}

	public String getGroupName() {
		return this.groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public Integer getPermission() {
		return this.permission;
	}

	public void setPermission(Integer permission) {
		this.permission = permission;
	}

	public Date getRegisterTime() {
		return this.registerTime;
	}

	public void setRegisterTime(Date registerTime) {
		this.registerTime = registerTime;
	}

	public Date getModifyTime() {
		return this.modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	public Date getLastLoginTime() {
		return this.lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	public String getHomePageUrl() {
		return homePageUrl;
	}

	public void setHomePageUrl(String homePageUrl) {
		this.homePageUrl = homePageUrl;
	}

	public String getSignature() {
		return signature;
	}

	public void setSignature(String signature) {
		this.signature = signature;
	}
	
	public String getDisplayName(){
		return this.userName + "(" + this.loginName + ")";
	}

	public String getAreaName() {
		Area area = AreaManager.getInstance().getById(areaId);
		
		return area != null ? area.getName() : "";
	}
	
	
	
}